package hxm.monads;

/**
 * A monad for working with lists.
 * 
 * @author Simon Krajewski
 */

@unify("Iterable")
class ListMonad 
{

	static public function bind<A, B>(a:List<A>, f:A -> List<B>):List<B>
	{
		var ret = new List();
		for (li in a)
			for  (el in f(li))
				ret.push(el);
		return ret;
	}
	
	static public inline function yield<A>(a:A):List<A>
	{
		var list = new List<A>();
		list.add(a);
		return list;
	}

	static public var zero = new List();
}